<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>模块管理</title>
    <link rel="stylesheet" type="text/css" href="layui/css/layui.css" />
	<script src="layui/layui.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>

<!-- 设置父节点表单 -->
	<div id="addfdiv" style="display: none; margin-top: 20px;">
		<form class="layui-form" lay-filter="addfather" id="addfather" action="">
			<div class="layui-form-item">
				<label class="layui-form-label">父节点名称:</label>
				<div class="layui-input-inline" style="width: 200px;">
					<input type="text" name="mname" class="layui-input"
						lay-verify="required|vname"> <input type="hidden"
						name="Name" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">权重：</label>
				<div class="layui-input-inline" style="width: 200px;">
					<input type="text" name="mweight" class="layui-input"
						lay-verify="required|vname">
				</div>
			</div>

			<div class="layui-btn-container" style="text-align: center;">
				<button class="layui-btn" lay-filter="addfbtn" lay-submit="">提交</button>
			</div>

		</form>
	</div>

	<!-- 添加子节点表单 -->
	<div id="addzdiv" style="display: none; margin-top: 20px;">
		<form class="layui-form" lay-filter="addzform" id="addzform" action="">
			<div class="layui-form-item">
				<label class="layui-form-label">节点名称:</label>
				<div class="layui-input-inline" style="width: 200px;">
					<input type="text" name="mname" class="layui-input"
						lay-verify="required|vname">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">父节点:</label>
				<div class="layui-input-inline" style="width: 200px;">
					<input type="text" name="mparentid" class="layui-input"
						lay-verify="required|vname">
				</div>
			</div>
			
			<div class="layui-form-item">
				<label class="layui-form-label">路径:</label>
				<div class="layui-input-inline" style="width: 200px;">
					<input type="text" name="mpath" class="layui-input"
						lay-verify="required|vname">
				</div>
			</div>

        <div class="layui-form-item">
				<label class="layui-form-label">权重:</label>
				<div class="layui-input-inline" style="width: 200px;">
					<input type="text" name="mweight" class="layui-input"
						lay-verify="required|vname">
				</div>
			</div>

			<div class="layui-btn-container" style="text-align: center;">
				<button class="layui-btn" lay-filter="addbtn" lay-submit="">添加</button>
			</div>
		</form>
	</div>





<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
  <legend>模块管理</legend>
</fieldset>

	<header class="larry-personal-tit">
			<button class="layui-btn" style="margin-left: 600px" id="addz">添加子节点</button>
			<button class="layui-btn layui-btn-normal" id="addf">设置父节点</button>
		</header>
		
  <div id="test1" style="margin-left:250px;margin-top:50px; float:left;"></div>
  
 <div class="larry-personal-body clearfix" style="float:right;margin-right:450px;margin-top:50px;">
 <!-- 页面表单 -->
			<form class="layui-form col-lg-5"  lay-filter="addfform" id="addfform" action=""  method="post">
				<div class="layui-form-item">
					<label class="layui-form-label">父节点编号</label>
					<div class="layui-input-block">  
						<input type="text" id="ParentId1" name="mparentid"  autocomplete="off"  class="layui-input"  placeholder="输入父节点编号" >
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">节点编号</label>
					<div class="layui-input-block">
						<input type="text" id="Id1"  name="mid"  autocomplete="off" class="layui-input" placeholder="输入节点编号" >
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">节点名称</label>
					<div class="layui-input-block">
						<input type="text" id="title1"  name="mname"  autocomplete="off" class="layui-input" placeholder="输入节点名称">
					</div>
				</div>
			 <div class="layui-form-item">
					<label class="layui-form-label">路径</label>
					<div class="layui-input-block">
						<input type="text" id="href1"  name="mpath"  autocomplete="off" class="layui-input" placeholder="输入路径">
					</div>
				</div>
			
				<div class="layui-form-item">
					<label class="layui-form-label">权重</label>
					<div class="layui-input-block">
						<input type="text" id="Weight1"  name="mweight"  autocomplete="off" class="layui-input" placeholder="输入权重">
					</div>
				</div>
				
				
				<div class="layui-form-item">
					<div class="layui-input-block">
						<button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
						<button type="reset" class="layui-btn layui-btn-primary">重置</button>
					</div>
				</div>
			</form>	
		</div>
		
	<table class="layui-hide" id="demo" lay-filter="vfilter"></table>	
		
  <script>
  layui.use(['layer','form','tree','table'], function(){
    var tree = layui.tree;
    var layer = layui.layer;
    var table = layui.table;
    var form = layui.form;
    var $ =layui.$;
  //开启节点操作图标,树的实列
	  $.get("/tree",function(date){
	  
	  	data2=[{
	  		 title: date.title
		    ,id: date.id
		    ,children:[{
		    	date
		    }]
	  	}]	
	  	
	  	tree.render({
	    elem: '#test1'
	    ,data: date
	    ,showCheckbox: true
	    ,edit: ['add', 'update', 'del'] //操作节点的图标
	    ,click: function(obj){
	    	var data=obj.date;
	   // layer.msg(JSON.stringify(obj.data));
	    $("#ParentId1").val(obj.data.parentId);
	    $("#title1").val(obj.data.title);
	    $("#Id1").val(obj.data.id);
	    $("#href1").val(obj.data.href);
	    $("#Weight1").val(obj.data.weight);
	    }
	  });
	  	
	  	treeMethod={
			  	add:function(obj){
			  	
			  			layer.open({
							type:1,
							title:'添加节点',
							content:$("#addzdiv"),
							area:['350px','500px']
						})
			  	},
			  	update:function(){
			  		//alert("已经将模块的修改功能赋予角色");
			  		//alert(JSON.stringify(obj.data));
			  	},
			  	del:function(obj){
			  		alert("已经将模块的删除功能赋予角色");
			  			$.post("deleteModules", {Id:obj.data.Id}, function(res) {
							if(res>0) {
								layer.alert("删除成功！", {
									icon: 1
								}, function(index) {
									loacation.reload();
									layer.closeAll();
								});
							} else {
								layer.alert("删除失败！", {
									icon: 2
								});
							}
						}, "json");  
			  	}
			  }
	  	
	  },"json");
  
	 
    
	//子节点
		$("#addz").click(function() {
				layer.open({
					type: 1,
					title: '添加子节点',
					content: $("#addzdiv"),
					area: ['350px', '500px']
				});
		});  
	
		//父节点
		$("#addf").click(function() {
				layer.open({
					type: 1,
					title: '添加父节点',
					content: $("#addfdiv"),
					area: ['350px', '500px']
				});
		});   
	
		//提交子节点添加
		form.on('submit(addbtn)', function(data) {
			var data = $("#addzform").serialize();
			$.post("addModules", data, function(res) {
				if(res>0) {
					layer.alert("添加成功！", {
						icon: 1
					}, function(index) {
						location.reload();
						layer.closeAll();
					});
				} else {
					layer.alert("添加失败！", {
						icon: 2
					});
				}
			}, "json");
			return false;
		});
		
		//提交父节点添加
		form.on('submit(addfbtn)', function(data) {
			var data = $("#addfather").serialize();
			$.post("addModules", data, function(res) {
				if(res>0) {
					layer.alert("添加成功！", {
						icon: 1
					}, function(index) {
						location.reload();
						layer.closeAll();
					});
				} else {
					layer.alert("添加失败！", {
						icon: 2
					});
				}
			}, "json");
			return false;
		});
		
		//提交修改表单
		form.on('submit(demo1)', function(data) {
			var data = $("#addfform").serialize();
			$.post("updateModules", data, function(res) {
				if(res> 0) {
					layer.alert("修改成功！", {
						icon: 1
					}, function(index) {
						location.reload();
						layer.closeAll();
					});
				} else {
					layer.alert("修改失败！", {
						icon: 2
					});
				}
			}, "json");
			return false;
		});
    
  });
  </script>
</body>
</html>